{{extend ("./layout")}}
<!-- 列表内容 -->
{{#block ("body")}}
<div class="panel panel-default">
      <div class="panel-heading">
          <ol class="breadcrumb">
            <li><a href="#">首页</a></li>
            <li><a href="#">视频</a></li>
            <li class="active">列表</li>
          </ol>
      </div>

      <div class="panel-heading">
          <div class="input-group">
            <span class="input-group-addon">视频标题</span>
            <input type="text" id = "searchId" style="width:300px;margin-right:10px;" class="form-control" value = "{{keyword}}" placeholder="请输入是查找的视频标题">
            <input type="button" class="btn btn-primary" onclick="search();" style="margin-right:10px;" value="查找">
            <input type="button" class="btn btn-primary" id = "addId" onclick="window.location.href = '/video/add' " value="新增">
          </div>
      </div>

      <div class="panel-body">
        <div>
          <!-- 表格 -->
          <table class="table table-bordered">
            <thead>
              <tr>
                <th>#</th>
                <th>标题</th>
                <th>排序号</th>
                <th>视频Id</th>
                <th>操作</th>
              </tr>
            </thead>
            <tbody>
                {{#each(list)}}
                    <tr>
                        <td>{{this.vid}}</td>
                        <td>{{this.vtitle}}</td>
                        <td>{{this.vsortno}}</td>
                        <td>{{this.vvideoid}}</td>
                        <td>
                          <input type="button" class="btn btn-success" value="编辑" onclick="window.location.href='/video/edit/{{this.vid}}'"> | 
                          <input type="button" class="btn btn-danger" value="删除" onclick="remove({{this.vid}})"> 
                        </td>
                  </tr>
                {{/each}}
            </tbody>
          </table>
          <div>
            <nav>
              <ul class="pagination">
                <!-- 上翻页 -->
                {{#if( pageIndex===0 )}}
                <li class="disabled"><a href="#">«</a></li>
                {{else}}
                <li><a href="/video/list?pageindex={{pageIndex-1}}&pagesize=2&keyword={{keyword}}">«</a></li>
                {{/if}}
                <!-- 中间页码 -->
                {{#each(pages)}}
                  {{#if( pageIndex===this )}}
                    <li class="active"><a href="/video/list?pageindex={{this}}">
                    {{this+1}} <span class="sr-only">(current)</span></a></li>
                  {{else}}
                    <li class=""><a href="/video/list?pageindex={{this}}">
                    {{this+1}} <span class="sr-only">(current)</span></a></li>
                  {{/if}}
                {{/each}}
                <!-- 下翻页 -->
                {{#if( pageIndex===pagetotal-1 )}}
                  <li class="disabled"><a href="#">«</a></li>
                {{else}}
                   <li><a href="/video/list?pageindex={{pageIndex+1}}&pagesize=2&keyword={{keyword}}">»</a></li>
                {{/if}}

              </ul>
            </nav>
          </div>
        </div>
        </div>
      </div>
</div>
<script type="text/javascript">
  //点击查找.通过地址栏传参,服务器接收参数,然后去数据库查询,同时后台也会将关键字返回浏览器,显示
  function search(){
    window.location.href='/video/list?keyword='+$("#searchId").val();
  }
  //删除
  function remove(vid){
    if (confirm("真的要删除该条数据吗？")) {
            $.getJSON('/video/delete/'+vid,null,function(jsObj){
                if (jsObj.status=="1") {
                  alert(jsObj.message);
                  window.location.href = "/video/list";
                }else{
                  alert(jsObj.message);
                }
            });
          }
  }
</script>
{{/block}}
